# -*- coding: utf-8 -*-
"""
Created on Wed Jan 16 09:53:08 2019

@author: 89580
"""
import socket 

HOST, PORT = '', 8888

listen_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST,PORT))
listen_socket.listen(1)
print ('Serving HTTP on port %s ...' % PORT)

def Processing(request):
    uid = request.split("key=")[1].split(" ")[0]
    return uid


def gp(uid):
    click_action = {}
    file = open("./2000logfile.txt")
    for line in file.readlines():
        line = line.strip()
        ls = line.split("&")
        if (len(ls)==1 or ls[7] !="1"):
            continue
        if ls[1] not in click_action.key():
            click_action[ls[1]] =[]
        click_action[ls[1]].append(ls[4])
    if uid in click_action.keys():
             return "&&".join(click_action[uid])
         
def log_process(request):
    print ("xiao ming' log")
    print (request)
    return "yes i got it"

while True:
    client_connection, client_address =listen_socket.accept()
    request = client_connection.recv(1024)
    
    http_response = log_process(request)
    client_connection.sendall(http_response)
    client_connection.close()
    